package xyz.kongbai121.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.kongbai121.demo.domain.RespBean;
import xyz.kongbai121.demo.service.IOpinionService;
import xyz.kongbai121.demo.util.SensitiveWord;
import xyz.kongbai121.demo.util.UserPowerException;


/**
 * 树洞评论处理控制器
 *
 * @author 空白
 */
@RestController
@RequestMapping("/opinion")
public class OpinionController {

    @Autowired
    private IOpinionService service;

    @RequestMapping("/deliver")
    public RespBean commentDeliver(String content, Long treeId, Long opinionId, Long upOpinionId, String token) {
        //敏感字符处理
        String securityContent = SensitiveWord.getSensitiveWord().filterInfo(content);
        String msg = service.save(securityContent, treeId, opinionId, upOpinionId, token);
        return new RespBean(true, msg);
    }

    @RequestMapping("/delete")
    public RespBean commentDelete(Long id, String token) {
        String msg = service.delete(id, token);
        return new RespBean(true, msg);
    }

    @RequestMapping("/list")
    public RespBean list(Long treeId) {
        return new RespBean(true, service.list(treeId));
    }

}
